#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include <boost/bind.hpp>
#include <boost/lexical_cast.hpp>
int toInt(const string& s)
{
	return boost::lexical_cast<int>(s);
}
template<typename X>
void print( const X& s)
{
	cout << s << endl;
}
int main(int argc, char* argv[])
{
	vector<string> v;
	v.push_back("1");
	v.push_back("2");
	v.push_back("3");
	v.push_back("4");
	
	cout << "before push size=" << v.size() << endl;
	bind(&vector<string>::push_back, v, _1)("5");
	cout << "after push size=" << v.size() << endl;
	cout << "=================================" << endl;
	cout << "before push using boost::ref size=" << v.size() << endl;
	bind(&vector<string>::push_back, boost::ref(v), _1)("5");
	cout << "after push boost::ref size=" << v.size() << endl;
	cout << "=================================" << endl;
	vector<int> v2;
	cout << "before for_each to int and push_back size=" << v2.size() << endl;
	for_each(v.begin(), v.end(), bind(&vector<int>::push_back, boost::ref(v2), bind(toInt, _1)));
	cout << "after for_each push_back size=" << v2.size() << endl;
	cout << "=================================" << endl;
	cout << "before for_each print out" << endl;
	for_each(v.begin(), v.end(), print<string>); 
	for_each(v2.begin(), v2.end(), print<int>); 
	cout << "after for_each print out" << endl;
	cout << "=================================" << endl;
}


